/**
 * Copyright (C) 2008 Christopher Allen Ogden
 *
 *     This file is part of Odysi.
 *
 *  Odysi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Odysi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Odysi.  If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once
#include <SDL.h>
#include <SDL_opengl.h>
#include <CEGUI.h>
#include <CEGUIDefaultResourceProvider.h>
#include <RendererModules/OpenGLGUIRenderer/openglrenderer.h>
#include <string>
#include <lua.hpp>
#include "std.h"

/**
 * Handles a mouse button down.
 *
 * @param button    The button pressed.
 * @return          True if it was handled, false otherwise.
 */
bool handleMouseDown(Uint8 button);

/**
 * Handles a mouse button up.
 *
 * @param button    The button pressed.
 * @return          True if it was handled, false otherwise.
 */
bool handleMouseUp(Uint8 button);

/**
 * Injects the CEGUI time pulse.
 *
 * @param last_time_pulse   Last time pulse injected.
 */
void injectTimePulse(double& lastTimePulse);

/**
 * Converts an SDL key to a CEGUI key.  Used for keyboard input.
 *
 * @param key   SDL key.
 * @return      CEGUI key.
 */
CEGUI::uint SDLKeyToCEGUIKey(SDLKey key);

/**
 * Initialize CEGUI.
 *
 * @param L Lua state for CEGUI to use.
 */
void initCEGUI(lua_State *L);

/**
 * Set the CEGUI layout from a layout file.
 *
 * @param layout    Name of the layout file.
 */
void setCEGUILayout(const std::string &layout);

/**
 * Get a CEGUI value from a window.
 *
 * @param window    Name of the window to get the value of.
 * @return          Value in the window (as a string).
 */
inline std::string getCEGUIValue(const std::string &window)
{
    return CEGUI::System::getSingleton().getGUISheet()->getChild(window)->getText().c_str();
}

/**
 * Get a CEGUI int value from a window.
 *
 * @param window    Name of the window to get the value of.
 * @return          Value in the window (as an int).
 */
inline int getCEGUIInt(const std::string &window)
{
    return boost::lexical_cast<int>(getCEGUIValue(window));
}
